﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Simple.Tools;

/*********************************************************
 * 命名空间 Simple.Framework.Configuration
 * 接口名称 HostConfiguration
 * 开发人员：zdm
 * 创建时间：2023/12/12 13:41:37
 * 描述说明：
 * 更改历史：
 * 
 * *******************************************************/
namespace Simple.Framework.Configuration
{
	public class HostConfiguration
	{
		public HostConfiguration()
		{

			ipAddress = ToolSimpleCheck.GetLocalHostFirstOrDefault();
			Backlog = 310;
		}

		public void SetIpAddress(string IpString)
		{
			if (IpString == "localhost")
			{
				ipAddress = ToolSimpleCheck.GetLocalHostFirstOrDefault();
				return;
			}
			if (!IPAddress.TryParse(IpString, out ipAddress))
				throw new Exception("ip地址不合法请检查!");

		}
		public IPAddress GetIpAddress()
		{
			if (ipAddress == null)
			{
				SetIpAddress(IpAddress);
			}
			return ipAddress;
		}
		public int Port { get { return port; } set { if (value <= 1000) throw new Exception(); port = value; } }
		public string IpAddress { get { return ipAddress == null ? "" : ipAddress.ToString(); } set { SetIpAddress(value); } }
		public SocketType SocketType { get { return socketType; } set { socketType = value; } }
		public ProtocolType ProtocolType { get { return protocolType; } set { protocolType = value; } }
		public int Backlog { get { return backlog; } set { backlog = value; } }

		private IPAddress ipAddress;
		private int port;
		private SocketType socketType;
		private ProtocolType protocolType;
		private int backlog;

	}
}
